﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace uzing
{
    public class uzCTcpClient
    {
        [DllImport("Inklude.dll", SetLastError = true)]
        private static extern IntPtr _inklude_tcp_client_create_instance();

        [DllImport("Inklude.dll", SetLastError = true)]
        private static extern void _inklude_tcp_client_initialize(IntPtr _ptr, uint nRecvPort);

        [DllImport("Inklude.dll", SetLastError = true)]
        private static extern void _inklude_tcp_client_set_distination(IntPtr _ptr, [MarshalAs(UnmanagedType.LPWStr)]string Address, uint nPort);

        [DllImport("Inklude.dll", SetLastError = true)]
        private static extern uint _inklude_tcp_client_send(IntPtr _ptr, byte[] buffer, uint sendSize);

        [DllImport("Inklude.dll", SetLastError = true)]
        private static extern uint _inklude_tcp_client_receive(IntPtr _ptr, byte[] buffer, uint sendSize);

        private IntPtr pInstance;
        public uzCTcpClient()
        {
            pInstance = _inklude_tcp_client_create_instance();
        }

        public void Initialize(uint nRecvPort)
        {
            _inklude_tcp_client_initialize(pInstance, nRecvPort);
        }

        public void SetDestination(string RemoteAddress, uint nRemotePort)
        {
            _inklude_tcp_client_set_distination(pInstance, RemoteAddress, nRemotePort);
        }

        public uint Send(byte[] buffer, uint sendSize)
        {
            return _inklude_tcp_client_send(pInstance, buffer, sendSize);
        }

        public uint Receive(byte[] buffer, uint recvSize)
        {
            return _inklude_tcp_client_receive(pInstance, buffer, recvSize);
        }
    }
}
